﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using MetadataBasedConfigArch.Framework;
using System.ComponentModel;

namespace MetadataBasedConfigArch.Web
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Util.TenantID <=0 || Util.UserID <=0)
            {
                Response.Redirect("~/Login.aspx");
                return;
            }
                       
            using (Framework.IMetadataBasedEntityProvider entityProvider = new Model.DataEntityProvider(EntityUtil.MDAConnectionString))
            {
                Model.Page page = entityProvider.Load<Model.Page>().FirstOrDefault();
                if (page != null)
                {
                    page.LoadConfigurableInfos(entityProvider);
                }
                page.SetConfigurableInfo("Title", 4);

                //List<Model.Page> allPages = entityProvider.Load<Model.Page>().ToList();
                //allPages.ForEach(p => p.LoadExtendProperties(entityProvider));

                //ConfigMetadata configMetadata = new ConfigMetadata(entityProvider);
                //configMetadata.Load(Util.TenantID, 1, true);

                entityProvider.Save();
            }
        }
    }

    public class Book
    {
        public int ID { get; set; }

        public string Name { get; set; }

        public Dictionary<string, object> ExtendProperties { get; set; }
    }
}